When you save your model, the NHibernate designer creates C# or Visual Basic class definitions and XML mapping documents for your entities.

To use the generated classes with NHibernate, you must load the mapping documents into your configuration. The easiest way to do this is to use the generated ConfigurationHelper class. The CreateConfiguration method will create a NHibernate Configuration object with the mappings all loaded.

If you gave the model a non-blank name, then you’ll need to prefix this to the ConfigurationHelper class name, e.g. SalesModelConfigurationHelper.
 

If you use Fluent NHibernate mappings, you don’t need to use ConfigurationHelper. Just load the assembly mappings using the normal Fluent NHibernate API.
 

CopyC#
Configuration configuration = ConfigurationHelper.CreateConfiguration();
ISessionFactory sessionFactory = configuration.BuildSessionFactory();

Right-click the model background and choose Get Started to see sample code for loading the configuration and building a session factory. The Get Started screen also contains a Configure button which will update the configuration file for you.
 

You must also supply NHibernate database settings such as the database type and connection string. You will typically do this through app.config or web.config. Right-click the model background and choose Get Started for suggested entries that you can copy into your config file.
 

Sometimes you may want to create the Configuration object yourself, for example to customise its properties before loading the configuration from file. In this case you can load the designer-generated mapping documents by calling the generated ConfigurationHelper.ApplyConfiguration method.

CopyC#
Configuration configuration = new Configuration();
configuration.AddProperty(somePropertyDictionary);
configuration.Configure();

ConfigurationHelper.ApplyConfiguration(configuration);